package com.sicheng.algorithm.recursive;

/**
 * @author zsc
 * @version 1.0
 * @date 2021/9/14 22:01
 */
public class Hanoi {
    public static void main(String[] args) {
        hanoi(4);
    }

    public static void hanoi(int n) {
        if (n >= 1)
            hanoi(n, 'A', 'B', 'C');
    }

    private static void hanoi(int n, char A, char B, char C) {
        if (n == 1) {
            System.out.println("第1个盘子从" + A + "->" + C);
        } else {
            //把最上面的盘子从 A->B
            hanoi(n - 1, A, C, B);
            //最下面的盘子从  A->C
            System.out.println("第" + n + "个盘子从" + A + "->" + C);
            //把最上面的盘子从 B->C
            hanoi(n - 1, B, A, C);
        }

    }
}
